#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
Sqr(x), k >>= 1;
}
return res;
}
// int f[35][2];
const LL INF = 1e18;
int n, m, r;
int a[35], b[35], k[35], p[35];
int w[35], g[35][35];
LL ans;
void dfs(int x, int op)
{
// printf("now : ");
// for(int i = 1; i <= n; ++i)
// printf("%d ", w[i]);
// puts("");
if((m - x + 1 + 1 ) & 1)
{
LL res = 0;
for(int i = 1; i <= n; ++i)
res += 1LL * w[i] * k[i];
chkmx(ans, res);
}
if(x == m + 1) return;
if(op == 0)
{
for(int i = 1; i <= n; ++i) g[x][i] = w[i];
for(int i = 1; i <= n; ++i) w[i] = g[x][p[i]] + r;
dfs(x + 1, 0);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
for(int i = 1; i <= n; ++i) w[i] ^= b[i];
dfs(x + 1, 1);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
}
if(op == 1)
{
for(int i = 1; i <= n; ++i) g[x][i] = w[i];
for(int i = 1; i <= n; ++i) w[i] = g[x][p[i]] + r;
dfs(x + 1, 0);
for(int i = 1; i <= n; ++i) w[i] = g[x][i];
}
}
int main()
{
// f[1][0] = f[1][1] = 1;
// for(int i = 2; i <= 30; ++i)
// {
// f[i][0] = f[i - 1][0] + f[i - 1][1];
// f[i][1] = f[i - 1][0];
// }
// printf("%d\n", f[30][0] + f[30][1]);
scanf("%d %d %d", &n, &m, &r);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), w[i] = a[i];
for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
for(int i = 1; i <= n; ++i) scanf("%d", &k[i]);
for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
ans = -INF;
dfs(1, 0);
printf("%lld\n", ans);
return 0;
}
1029A - Many Equal Substrings | 1675D - Vertical Paths |
1271C - Shawarma Tent | 805A - Fake NP |
1163A - Eating Soup | 787A - The Monster |
807A - Is it rated | 1096A - Find Divisible |
1430C - Numbers on Whiteboard | 1697B - Promo |
208D - Prizes Prizes more Prizes | 659A - Round House |
1492C - Maximum width | 171B - Star |
1512B - Almost Rectangle | 831B - Keyboard Layouts |
814A - An abandoned sentiment from past | 268C - Beautiful Sets of Points |
1391C - Cyclic Permutations | 11A - Increasing Sequence |
1406A - Subset Mex | 1365F - Swaps Again |
50B - Choosing Symbol Pairs | 1719A - Chip Game |
454B - Little Pony and Sort by Shift | 1152A - Neko Finds Grapes |
1719B - Mathematical Circus | 1719C - Fighting Tournament |
1642A - Hard Way | 285C - Building Permutation |